<?php

class AdvertiseController extends Controller {
    public function actionIndex() {
        $this->render('index');
    }

    public function actionCreate() {
        $detect = new Mobile_Detect;
        if ($detect->isMobile()) {
            $this->layout = '//layouts/main_mobile';
        }
        $model = new Advertise;
        Yii::app()->language = 'vi';

        if (isset($_POST['Advertise'])) {
            $model->attributes = $_POST['Advertise'];
            $model->phone = $_POST['Advertise']['phone'];
            $model->created_date = time();
            if ($model->save()) {
                Yii::app()->user->setFlash('success', "Đã đăng tin thành công, vui lòng chờ kiểm duyệt.");
                $this->redirect(HSUrl::getMapUrl());
            }
        }

        $this->render('create', array(
            'model' => $model,
            'categories' => AdCategory::model()->findAll()
        ));
    }
}